﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Widgetsphere.Autos.FacetedNavigation;

namespace Widgetsphere.Autos.Websitev2.Objects
{
	public class RepositoryHelper
	{
		private static RepositoryHelper _instance = null;
		private ListingResults _masterResults = null;
		public ListingResults MasterResults
		{
			get
			{
				if (_masterResults == null)
				{
					using (var factory = RepositoryConnection.GetFactory())
					{
						var service = factory.CreateChannel();
						var query = new ListingQuery();
						_masterResults = RepositoryConnection.QueryData(query, service);
					}
				}
				return _masterResults;
			}
		}

		private RepositoryHelper()
		{
		}

		public static RepositoryHelper GetInstance()
		{
			if (_instance == null)
				_instance = new RepositoryHelper();
			return _instance;
		}

		public ListingResults Query(ListingQuery query)
		{
			using (var factory = RepositoryConnection.GetFactory())
			{
				var service = factory.CreateChannel();
				return RepositoryConnection.QueryData(query, service);
			}
		}

	}
}